| Conditions | 1 |
| Paths | 32 |
| Total Lines | 80 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | $(document).ready(function() { |
||
| 2 | function ValidateDate(dtValue) { |
||
| 3 | var dtRegex = new RegExp(/\b\d{1,2}[\/-]\d{1,2}[\/-]\d{4}\b/); |
||
| 4 | return dtRegex.test(dtValue); |
||
| 5 | } |
||
| 6 | |||
| 7 | //---------------------------- EFFECT MATERIAL ON INPUT INPUT -----------------------------// |
||
| 8 | $('.block input').focus(function() { |
||
| 9 | $parent = $(this).parent(); |
||
|
|
|||
| 10 | $parent.addClass('is-focused has-label'); |
||
| 11 | $parent.removeClass('invalid'); |
||
| 12 | }); |
||
| 13 | |||
| 14 | $('.block input').blur(function() { |
||
| 15 | $parent = $(this).parent(); |
||
| 16 | $this = $(this); |
||
| 17 | |||
| 18 | var type = $this.attr("type-val"); |
||
| 19 | var min = $this.attr("min"); |
||
| 20 | var max = $this.attr("max"); |
||
| 21 | |||
| 22 | if (type == "string") { |
||
| 23 | if ($this.val() == "") { |
||
| 24 | $parent.addClass('invalid'); |
||
| 25 | $parent.removeClass('has-label'); |
||
| 26 | } |
||
| 27 | else if (($this.val().length < min) || ($this.val().length > max)) { |
||
| 28 | $parent.addClass('invalid'); |
||
| 29 | } |
||
| 30 | } |
||
| 31 | else if (type == "date") { |
||
| 32 | if (($this.attr('name') == "date") && (!ValidateDate($this.val()))) { |
||
| 33 | $parent.addClass('invalid'); |
||
| 34 | } |
||
| 35 | } |
||
| 36 | |||
| 37 | $parent.removeClass('is-focused'); |
||
| 38 | }); |
||
| 39 | |||
| 40 | $('.block input').each(function() { |
||
| 41 | if (($(this).val() != '') || ($(this).val() != 0)) { |
||
| 42 | $(this).parent().addClass('has-label'); |
||
| 43 | } |
||
| 44 | }); |
||
| 45 | |||
| 46 | |||
| 47 | $('.block textarea').focus(function() { |
||
| 48 | $parent = $(this).parent(); |
||
| 49 | $parent.addClass('is-focused has-label'); |
||
| 50 | $parent.removeClass('invalid'); |
||
| 51 | }); |
||
| 52 | |||
| 53 | $('.block textarea').blur(function() { |
||
| 54 | $parent = $(this).parent(); |
||
| 55 | $this = $(this); |
||
| 56 | |||
| 57 | var type = $this.attr("type-val"); |
||
| 58 | var min = $this.attr("min"); |
||
| 59 | var max = $this.attr("max"); |
||
| 60 | |||
| 61 | if (type == "string") { |
||
| 62 | if ($this.val() == "") { |
||
| 63 | $parent.addClass('invalid'); |
||
| 64 | $parent.removeClass('has-label'); |
||
| 65 | } |
||
| 66 | else if (($this.val().length < min) || ($this.val().length > max)) { |
||
| 67 | $parent.addClass('invalid'); |
||
| 68 | } |
||
| 69 | } |
||
| 70 | |||
| 71 | $parent.removeClass('is-focused'); |
||
| 72 | }); |
||
| 73 | |||
| 74 | $('.block textarea').each(function() { |
||
| 75 | if (($(this).val() != '') || ($(this).val() != 0)) { |
||
| 76 | $(this).parent().addClass('has-label'); |
||
| 77 | } |
||
| 78 | }); |
||
| 79 | //---------------------------- END EFFECT MATERIAL ON INPUT INPUT -----------------------------// |
||
| 80 | }) |